use mlibs::periph::{rcc::RCC, tim::TIM2};



pub fn init() {
    RCC.apb1enr.modify(|_, w| w.tim2en().enabled() );
    TIM2.cr1.reset();
    TIM2.cr2.reset();
    TIM2.arr.write(|w| w.arr().bits(0xFFFF));
    TIM2.psc.write(|w| w.psc().bits(72 - 1));
    TIM2.cr1.write(|w| w.cen().enabled());
}


pub fn delay_us(us: u16) {
    TIM2.cnt.reset();
    while TIM2.cnt.read().cnt().bits() < us {}
}

pub fn delay_ms(ms: u32) {
    for _ in 0..ms {
        delay_us(1000);
    }
}
